import { isEmpty } from "lodash-es";

export class DictStorage {
  static KEY = "UI_CACHE_DB_DICT_DATA";

  static setDictList(value: any[]) {
    localStorage.setItem(this.KEY, JSON.stringify(value));
  }

  static getDictList() {
    const valueStr = localStorage.getItem(this.KEY) || "{}";
    let roleList = [];
    try {
      roleList = JSON.parse(valueStr);
    } catch (err) {}
    return roleList;
  }

  static getDictItemsByCode(code: string) {
    const allDicts = this.getDictList();
    if (isEmpty(allDicts) || !allDicts[code]) {
      return [];
    }

    return allDicts[code];
  }
}
